/*
 * Copyright (c) 2011-2022, baomidou (jobob@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.baomidou.mybatisplus.advance.query.enums;

import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;

/**
 * 前端高级查询API操作符
 * @author wanglei
 * @since 2022-03-14
 */
public enum OperatorEnum {

    EQ("="),
    NE("!="),
    GT(">"),
    GE(">="),
    LT("<"),
    LE("<="),
    BETWEEN("between"),
    NOT_BETWEEN("not_between"),
    LIKE("like"),
    NOT_LIKE("not_like"),
    LIKE_LEFT("like_l"),
    LIKE_RIGHT("like_r"),
    IS_NULL("is_null"),
    NOT_NULL("not_null"),
    IN("in"),
    NOT_IN("not_in"),
    ;

    /**
     * 操作符
     */
    private String operator;

    OperatorEnum(String operator){
        this.operator = operator;
    }

    public String getOperator(){
        return operator;
    }


    /**
     * 根据操作符获取枚举
     * @param operator  操作符
     * @return 操作符对应的枚举
     */
    public static OperatorEnum getByOperator(String operator){
        for (OperatorEnum value : OperatorEnum.values()) {
            if(value.operator.equals(operator)){
                return value;
            }
        }
        throw ExceptionUtils.mpe("This operator is not supported %s", operator);
    }

}
